<template>
  <div>8</div>
</template>

<script>
export default {

}
</script>

<style>
</style>
<template>
  <div id="app">
    <div>
      <span>姓名:</span>
      <input type="text"
             v-model="uname" />
    </div>
    <div>
      <span>年龄:</span>
      <input type="number"
             v-model="age" />
    </div>
    <div>
      <span>性别:</span>
      <select v-model="gender">
        <option value="男">男</option>
        <option value="女">女</option>
      </select>
    </div>
    <div>
      <button @click="add">添加</button>
      <button @click="xiugai">修改</button>
    </div>
    <div>
      <table border="1"
             cellpadding="10"
             cellspacing="0">
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
          <th>操作</th>
        </tr>
        <tr v-for="obj,index in arr"
            :key="index">
          <td>{{index+1}}</td>
          <td>{{obj.name}}</td>
          <td>{{obj.age}}</td>
          <td>{{obj.gender}}</td>
          <td>
            <button @click="del(index)">删除</button>
            <button @click="edit(index)">编辑</button>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      q: 0,
      uname: '',
      age: '',
      gender: '男',
      arr: [

      ]
    }

  },
  methods: {
    add () {
      if (!this.uname || !this.age) return alert('输入框必须都幼稚')
      this.arr.push({
        name: this.uname,
        age: this.age,
        gender: this.gender
      })
    },
    edit (i) {

      this.q = i

      this.uname = this.arr[i].name
      this.age = this.arr[i].age
      this.gender = this.arr[i].gender

    },
    xiugai (q) {
      console.log(this.arr[q]);
    },
    del (i) {
      this.arr.splice(i, 1)
    }

  }
}
</script>
